package mil.af.amc.adpetracker.web.helpers;

import mil.af.amc.adpetracker.model.Rank;
import mil.af.amc.adpetracker.service.RankService;
import mil.af.amc.radtaglibrary.tags.PageContextAwareBean;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.PageContext;
import java.util.List;

/**
 * View Helper for Rank objects
 *
 * @author TSgt Jason Ferguson
 */
@Service("rankViewHelper")
public class RankViewHelper implements PageContextAwareBean {

    private PageContext pageContext;

    @Autowired
    public void setPageContext(PageContext pageContext) {
        this.pageContext = pageContext;
    }

    private RankService rankService;

    @Autowired
    public void setRankService(RankService rankService) {
        this.rankService = rankService;
    }

    public List<Rank> getAll() {

        return rankService.getAll();

    }

    public Rank getById() {

        HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
        int rankId = Integer.parseInt(request.getParameter("rankId"));

        return rankService.getById(rankId);
    }
}
